home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 1.iso / ARGONET / PD / MATHS / RLAB / RLAB125.ZIP / !RLaB / toolbox / detrend < prev    next >
Text File  |  1994-05-08  |  639b  |  31 lines

  1. //-------------------------------------------------------------------//
  2.  
  3. //  Syntax:    detrend ( A )
  4.  
  5. //  Description:
  6.  
  7. //  Detrend removes a linear trend from a vector.
  8.  
  9. //  y = detrend (x) 
  10.  
  11. //  removes the best straight-line fit from the data in vector x and
  12. //  returns it in vector y. Detrend is often used prior to fft().
  13.  
  14. //-------------------------------------------------------------------//
  15.  
  16. detrend = function ( x )
  17. {
  18.   local (a, m, n, y);
  19.  
  20.   m = x.nr; n = x.nc;
  21.   m = max ( [m, n] );
  22.   y = reshape (x, prod (size (x)), 1);
  23.   a = [ (1:m)'/m, ones(m,1) ];
  24.   y = y - a*(a\y);
  25.   if (n != 1)
  26.   {
  27.     y = conj (y');
  28.   }
  29.   return y;
  30. };
  31.